package com.hkts.naturalgas.alarminformation.controller;


import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.hkts.naturalgas.utils.CustomPageUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hkts.naturalgas.utils.Result;
import com.hkts.naturalgas.utils.ResultUtil;
import com.alibaba.fastjson.JSON;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hkts.naturalgas.alarminformation.service.INaturalgasGateStationService;
import com.hkts.naturalgas.alarminformation.entity.NaturalgasGateStation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 * @author yck
 * @since 2020-09-11
 */
@RestController
@RequestMapping("/instrumentdata/naturalgasGateStation")
public class NaturalgasGateStationController {
    private final Logger logger = LoggerFactory.getLogger(NaturalgasGateStationController.class);

    @Autowired
    public INaturalgasGateStationService iNaturalgasGateStationService;

    /**
     * 分页查询数据
     *
     * @param page                  分页信息
     * @param naturalgasGateStation 查询条件
     * @return
     */
    @ResponseBody
    @GetMapping("/getNaturalgasGateStationPageList")
    public Result<Object> getHontUserList(Page<NaturalgasGateStation> page, NaturalgasGateStation naturalgasGateStation) {
        return ResultUtil.data(CustomPageUtils.getCustomPage(iNaturalgasGateStationService.selectPage(page, naturalgasGateStation)));
    }

    //获取所有门站
    @ResponseBody
    @GetMapping("/getNaturalgasGateStationList")
    public Result<Object> getGateStationList(NaturalgasGateStation naturalgasGateStation) {
        return ResultUtil.data(iNaturalgasGateStationService.selectList(naturalgasGateStation));
    }

    /**
     * 保存和修改公用的
     *
     * @param naturalgasGateStation 传递的实体
     * @return saveOrUpdate
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/naturalgasGateStationSave")
    public Result<Object> naturalgasGateStationSave(NaturalgasGateStation naturalgasGateStation) {
        iNaturalgasGateStationService.saveOrUpdate(naturalgasGateStation);
        return ResultUtil.success("保存成功");
    }

    /**
     * 根据id获取对象
     *
     * @param id 实体ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/naturalgasGateStationGetById")
    public Result<Object> naturalgasGateStationGetById(String id) {
        NaturalgasGateStation byId = iNaturalgasGateStationService.getById(id);
        return ResultUtil.data(byId);
    }

    /**
     * 根据id删除对象
     *
     * @param id 实体ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/naturalgasGateStationDelete")
    public Result<Object> hontUserDelete(String id) {
        iNaturalgasGateStationService.removeById(id);
        return ResultUtil.success("删除成功");
    }

    /**
     * 批量删除对象
     *
     * @param item 实体集合ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/naturalgasGateStationBatchDelete")
    public Result<Object> deleteBatchIds(String item) {
        List<String> ids = (List<String>) JSON.parse(item);
        iNaturalgasGateStationService.removeByIds(ids);
        return ResultUtil.success("删除成功");
    }

}
